import React,{ReactNode} from 'react';
import { connect } from "react-redux";
import { HashRouter,Route,Routes } from "react-router-dom";
import AuthRoute from './routers/AuthRouter';
import Router from "@/routers/index";
import { RouteObject } from './routers/interface';
import { rootRouter } from '@/routers/index';
import { it } from 'node:test';
const App = (props: any) => {


  const RouteAuthFun = (
    (routeList: any[]) => {
      return routeList.map(
        (item: {
          path: string;
          element: ReactNode;
          meta?:any,
          children?: any;
        }) => {
          return (
            <Route
              path={item.path}
              element = {item.element? 
                <AuthRoute  key={item.path}>               
                  {item.element}
                </AuthRoute>
              :null}
              key={item.path}
            >
              {/* 递归调用，因为可能存在多级的路由 */}
              {item?.children && RouteAuthFun(item.children)}
            </Route>
          );
        }
      );
    }
  );
  return <Routes>{RouteAuthFun(rootRouter)}</Routes>;
  // return <Router />;
}
const mapStateToProps = (state: any) => state.global;
export default connect(mapStateToProps)(App);